---
title: Sparse Vector Search
---

## Basic Usage

<Note>
  Creating a [sparse HNSW index](/search/sparse/index) over a table can
  significantly improve query times.
</Note>

```sql
-- Create a table with a sparse vector column
CREATE TABLE items (id bigserial PRIMARY KEY, embedding sparsevec(5));

-- Insert sparse vectors
INSERT INTO items (embedding) VALUES ('{1:1,3:2,5:3}/5'), ('{1:4,3:5,5:6}/5');
```

Sparse vectors can be searched using L2 distance, cosine distance, or inner product.

```sql
-- L2 distance
SELECT * FROM items ORDER BY embedding <-> '{1:3,3:1,5:2}/5' LIMIT 5;

-- Cosine distance
SELECT * FROM items ORDER BY embedding <=> '{1:3,3:1,5:2}/5' LIMIT 5;

-- Inner product
SELECT * FROM items ORDER BY embedding <#> '{1:3,3:1,5:2}/5' LIMIT 5;
```

Under the hood, ParadeDB uses `pgvector` for sparse vector search. Please refer to the [`pgvector` documentation](https://github.com/pgvector/pgvector?tab=readme-ov-file#sparse-vectors) for more details.
